﻿CREATE view fact_budget as 
SELECT 
		t1.*
		,z.Budget_monthly_2014
FROM
(	SELECT Monat, Zweck_Id, SUM(Betrag) as Betrag_per_Zweck_Monat
	FROM
	( SELECT	LEFT(Wertdatum,7) as Monat
			,Zweck_Id
			,Betrag
	  FROM [dbo].[99_final] where len(Wertdatum) = 10
	)t0
	GROUP BY Monat, Zweck_Id
)t1
JOIN dim_Zweck z ON t1.Zweck_Id = z.ZweckID